package com.oocl.july18homeworkBooks;

import impl.BookDaoImpl;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;

public class Run {
	public void run1() throws FileNotFoundException, IOException{
		ObjectInputStream oin= new ObjectInputStream(new FileInputStream("a.txt"));
		new BookDaoImpl().addBooksFromFile(oin);
	}
	public void run2() throws FileNotFoundException, IOException{
		ObjectInputStream oin= new ObjectInputStream(new FileInputStream("a.txt"));
		new BookDaoImpl().addBooksFromFileWithBatch(oin);
	}
	
	public static void main(String[] args) throws FileNotFoundException, IOException {
		long startTime=System.currentTimeMillis();
//		new Run().run1();//逐条顺序插入到数据库中，平均耗时18697毫秒=18.697秒
		new Run().run2();//批量插入到数据库中（每1000条），平均耗时1781毫秒=1.781秒
		long endTime=System.currentTimeMillis(); 
		System.out.println((endTime-startTime)+"ms");
	}
}
